import React from 'react';
import { Redirect } from 'react-router-dom'

// 私有路由
// 做过滤操作
const Beforeeach = (props) => {
  const { path, name, component: Comp, children, Auth } = props
  const token = localStorage.getItem('token')

  // 拦截非登录页面， 必须登录
  // 没有登录进入登录页面
  // if(path !== '/login' && !token) {
  //   return <Redirect to="/login"></Redirect>
  // }

  if(Auth && !token) {
    return <Redirect to="/login"></Redirect>
  }
  // 返回正常路由
  return <Comp { ...props } routes={ children }></Comp>

}

export default Beforeeach;
